package com.yangfei.mystudy1020.animation;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class AnimActivityListAdaptor extends RecyclerView.Adapter<AnimActivityListAdaptor.RocketViewHolder> {
    List<AnimData>  mitems;
    Context mContext;

    public AnimActivityListAdaptor(Context ctx,List<AnimData> items){
        mContext = ctx;
        mitems = items;
    }
    @NonNull
    @Override
    public RocketViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(android.R.layout.simple_list_item_1, parent, false);

        return new RocketViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RocketViewHolder holder, int position) {
        holder.title.setText(mitems.get(position).mName);
        holder.setTitleOnClickListener(mContext, mitems);
    }

    @Override
    public int getItemCount() {
        return mitems.size();
    }

    class RocketViewHolder extends RecyclerView.ViewHolder {
        public TextView title;
        private Context context;
        public RocketViewHolder(View itemView) {
            super(itemView);
            title = itemView.findViewById(android.R.id.text1);
        }

        public void setTitleOnClickListener(final Context context, final List<AnimData> items) {
            title.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    context.startActivity(items.get(getAdapterPosition()).intent);
                }
            });
        }
    }
}
